<?php
// src/Pyaf/GymBundle/Repository/CalendarioRepository.php
namespace Pyaf\GymBundle\Repository;

use Doctrine\ORM\EntityRepository;
/**
 * Description of CalendarioRepository
 *
 * @author Toshiba P755-S5272
 */
class CalendarioRepository extends EntityRepository{
    
    public function findAllOrderByNombre() {                
        return $this->getEntityManager()
                    ->createQuery('SELECT c FROM PyafGymBundle:Calendario c ORDER BY c.title ASC')
                    ->getResult();
    }
    
    public function findFecha($id) {                
        return $this->getEntityManager()
                    ->createQuery("SELECT c FROM PyafGymBundle:Calendario c WHERE c.id = $id")
                    ->getOneOrNullResult();
    }
    
    public function findJsonDate($id) {                
        return $this->getEntityManager()
                    ->createQuery("SELECT c FROM PyafGymBundle:Calendario c WHERE c.id = $id")
                    ->getArrayResult();
    }
    
    /**
     * 
     * @return type Array of Calendars Entity
     */
    public function retrieveAllEvents(){
        return $this->getEntityManager()
                    ->createQuery("SELECT c FROM PyafGymBundle:Calendario c ")
                    ->getArrayResult();
    }
    
    public function findRutinaByCurrentDate($currentDate){
        return $this->getEntityManager()
                    ->createQuery("SELECT c FROM PyafGymBundle:Calendario c WHERE c.start = '$currentDate' ")
                    ->getOneOrNullResult();
    }

    public function save($fecha){
        $this->saveFecha($fecha);
    }
    
    public function saveFecha($fecha) {
        $em = $this->getEntityManager();
        $em->persist($fecha);
        $em->flush();
    }
}

?>
